<?php

/**
 * 函数库
 * ============================================================================
 * Power By Tmac PHP MVC framework
 * $Author: xing7878@gmail.com $  <zwttmac@qq.com>
 * $Id: Func.class.php 57 2011-07-26 03:37:30Z xing7878@gmail.com $
 * http://www.t-mac.org；
 */
class Func
{

    /**
     * 替换url链接
     */
    static function replace_for_mod_rewrite()
    {
        //取config配置文件
        $configcache = Tmac::config('configcache.config', 'admin', '.inc.php');

        if (empty($configcache['cfg_rewrite'])) {
            return;
        }
        $cfg_indexurl = $configcache['cfg_indexurl'];
        $content = ob_get_contents();
        $urlin = array(
            "/index.php\?m=(news|wenhua)&(cid)=([0-9]*)&page=([0-9]*)/",
            "/index.php\?m=(news|wenhua)&(cid)=([0-9]*)/",
            "/index.php\?m=(show)&name=([a-zA-Z_]+)&(cid)=([0-9]*)/",
            "/index.php\?m=(showabout)&name=([a-zA-Z_]+)&(cid)=([0-9]*)/",
            "/index.php\?m=(show|page)&name=([a-zA-Z_]+)/",
            "/index.php\?m=(showabout|page)&name=([a-zA-Z_]+)/",
            "/index.php\?m=(anli)&(id)=([0-9]*)/",
            "/index.php\?m=(wenhua|news).show&aid=([0-9]*)/",
            "/index.php\?m=(anli|news|wenhua|hr)/",
        );
        $urlout = array(
            "{$cfg_indexurl}$1-$2-$3-$4.html",
            "{$cfg_indexurl}$1-$2-$3.html",
            "{$cfg_indexurl}$1-$2-$4.html",
            "{$cfg_indexurl}$1-$2-$4.html",
            "{$cfg_indexurl}$1-$2.html",
            "{$cfg_indexurl}$1-$2.html",
            "{$cfg_indexurl}$1-$3.html",
            "{$cfg_indexurl}$1show-$2.html",
            "{$cfg_indexurl}$1.html",
        );
        $s = preg_replace($urlin, $urlout, $content);
        ob_end_clean();
        //上面clean后再次开启压缩
        if ($GLOBALS['TmacConfig']['Common']['gzip']) {
            function_exists('ob_gzhandler') ? ob_start('ob_gzhandler') : ob_start();
        } else {
            ob_start();
        }

        echo $s;
    }

}